﻿@model CleverCMS.Cms.Services.ViewModels.PageEntryModel

@section HeadContent
{
    @if (Model.Page.ShowRating)
    {
        <link rel="stylesheet" href="@Url.Content("~/Content/jquery.rating.css")"/>
         <!-- jq rating -->
        <script type="text/javascript" src="@Url.Content("~/Scripts/jquery-2.0.2.js")"></script>
        <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.rating/jquery.rating.js")"></script>
        <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.rating/jquery.rating.pack.js")"></script>
        <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.rating/jquery.MetaData.js")"></script>
    }
}

@section PageContent
{

    <div @Html.Raw((User.Identity.IsAuthenticated && User.IsInRole("admin"))? "contenteditable='true' id='editable-content'" :  "") >
         @Html.Raw((Model).Page.PageContent)
    </div>
    
    @if (Model.Page.ShowRating)
    {
        <div class="row-fluid">
            <div class="span12">
                <br/>
                <b>Rating:</b> @{ Html.RenderPartial("_PageRatingControl", Model.Rating);}
            </div>
        </div>
    }

    @if (WebSecurity.IsAuthenticated)
    {
        <script type="text/javascript">
            $(document).ready(function() {
                CKEDITOR.disableAutoInline = true;
                CKEDITOR.inline("editable-content", {
                    on: {
                        blur: function (event) {
                            var id = @Model.Page.Id;
                            var request = jQuery.ajax({
                                url: "@Url.Action("UpdateContent","Page", new { area = "CleverCms.Admin" })",
                                type: "POST",
                                data: {
                                    content: event.editor.getData(),
                                    id: id
                                },
                                dataType: "html"
                            });

                        }
                    }
                });

                var editor = $("#editable-content");
                editor.css("border", "1px solid #4a8bc2");
                editor.before("<p style='color: #fff; background-color: #4a8bc2; padding: 5px; width: 220px; min-width: 210px; margin-bottom: 0px;'>Edit content</p>");
            });
        </script>
    }
    
    @if (Model.HasComments)
    {
        <div class="row-fluid">
            <div class="span12">
                @{ Html.RenderPartial("_PageCommentsControl", Model.PageComments);}
            </div>
        </div>
    }        
}